import menuApi from '@/api/menu'
let _this_;
const getData = () => _this_.curData || _this_.curData;
const getLoading = () => _this_.loading || _this_.loading;
let menusCheck = (rule, value, callback)=> {
    menuApi.doMenuCheck({code:getData().code,id:getData().id}).then(result=>{
        if(result.beans.data>0) {
            callback("编码已存在");
        } else {
            callback();
        }
    }).catch(error => {
        getLoading().submit = false;
        callback("获取编码异常");
    });
}
let menusNotOwnParent = (rule, value, callback)=> {
    if(getData().id == getData().parentId) {
        callback("不能选择自己");
    } else {
        callback();
    }
}
export default (context) => {
    _this_ = context;
    return {
        code: [
            {required: true, message: '请输入编码', trigger: 'blur'},
            {min: 1, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur'},
            {pattern: /^[a-zA-Z0-9_]+$/, message: '编码格式不正确', trigger: 'blur'}
        ],
        name: [
            {required: true, message: '请输入名称', trigger: 'blur'},
            {min: 1, max: 25, message: '长度在 3 到 20 个字符', trigger: 'blur'},
        ],
        enabled: [
            {required: true, message: '请输入状态', trigger: 'blue'}
        ],
        type: [
            {required: true, message: '请输入字典类型', trigger: 'blue'}
        ],
        isDefault: [
            {required: true, message: '请输入默认项', trigger: 'blue'}
        ],
        sort: [
            {required: true, message: '请输入排序', trigger: 'blue'},
            {pattern: /^[0-9]{1,3}$/, message: '必须为数字范围0到999', trigger: 'blue'},
        ],
        remark: [
            {min: 0, max: 30, message: '长度在 0 到 30 个字符', trigger: 'blur'},
        ]
    }
}
